package com.Helper;

import java.sql.Connection;
import java.sql.SQLException;

import com.Helper.*;
import com.database.*;

public class PaymentHelper 
{
	private static Connection connection = null;
	
	public static void Setup(Connection _connection) throws SQLException
	{
		connection = _connection;
	}
	
	public static boolean HasEnoughPoints(String username, int point) throws SQLException
	{
		CustomerDB db = new CustomerDB();
		db.Setup(connection);
		CustomerInfo info = db.GetSelectedCustomer(username);
				
		if (info.point >= point)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public static float GetPriceForSeat(String seat, String flight) throws SQLException
	{
		SeatHelper.Setup(connection);
		SeatInfo info = SeatHelper.GetSelectedSeat(seat, flight);
		
		if (info.getType().equals("Business"))
		{
			return 200;
		}
		else if (info.getType().equals("Economy Plus"))
		{
			return 150;
		}
		else
		{
			return 100;
		}
		
	}
	
	public static int GetPointNeededForSeat(String seat, String flight) throws SQLException
	{
		SeatHelper.Setup(connection);
		SeatInfo info = SeatHelper.GetSelectedSeat(seat, flight);
		
		if (info.getType().equals("Business"))
		{
			return 200;
		}
		else if (info.getType().equals("Economy Plus"))
		{
			return 150;
		}
		else
		{
			return 100;
		}
	}
	
	public static boolean IsItEnough(String seat, String flight, float paidPrice, int paidPoint) throws SQLException
	{
		float price = GetPriceForSeat(seat, flight);

		if (paidPrice + paidPoint >= price)
		{ 
			return true;
		}
		else
		{
			return false;
		}
	}

}
